<?php

namespace App\Http\Controllers\Api\v1;

use App\Http\Controllers\Controller;
use App\Http\Request\Api\v1\Sms\CheckRequest;
use App\Http\Request\Api\v1\Sms\SendRequest;
use App\Models\Arts\SmsCodeModel;
use App\Utils\AppResult;

/**
 * 短信板块
 * Author:panda
 * Email:joeyoung0314@qq.com
 * Class SmsController
 * @package App\Http\Controllers\Api\v1
 */
class SmsController extends Controller
{
    // 日志模块名称
    const LOG_MODULE = 'v1/SmsController';

    /**
     * 短信发送
     * @param SendRequest $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function send(SendRequest $request)
    {
        $params = $request->validated();
        $sms = new SmsCodeModel();
        if (!$sms->send($params['mobile'], $params['event'])) {
            return AppResult::response201($sms->getMessage());
        }

        return AppResult::response200('发送成功');
    }

    /**
     * 验证码校验
     * @param CheckRequest $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function check(CheckRequest $request)
    {
        $params = $request->validated();
        $sms = new SmsCodeModel();
        if (!$sms->check($params['mobile'], $params['code'], $params['event'])) {
            return AppResult::response201($sms->getMessage());
        }

        return AppResult::response200('校验通过');
    }
}
